namespace Test.ConsoleProgram.Algorithm.Solution
{
    [TestDescription("算法: 0226. 翻转二叉树")]
    public class No0226_InvertTree : AbsBaseTestItem
    {
        public class TreeNode
        {
            public int val;
            public TreeNode left;
            public TreeNode right;
            public TreeNode(int x) { val = x; }
        }

        /*
        翻转一棵二叉树。
        */

        public override void OnTest()
        {
            Assert.TestExe(InvertTree,
                new TreeNode(4)
                {
                    left = new TreeNode(2)
                    {
                        left = new TreeNode(1),
                        right = new TreeNode(3),
                    },
                    right = new TreeNode(7)
                    {
                        left = new TreeNode(6),
                        right = new TreeNode(9),
                    },
                },
                new TreeNode(4)
                {
                    right = new TreeNode(2)
                    {
                        right = new TreeNode(1),
                        left = new TreeNode(3),
                    },
                    left = new TreeNode(7)
                    {
                        right = new TreeNode(6),
                        left = new TreeNode(9),
                    },
                });
        }

        public TreeNode InvertTree(TreeNode root)
        {
            if (root == null) return null;
            TreeNode center = root.left;
            root.left = InvertTree(root.right);
            root.right = InvertTree(center);
            return root;
        }
    }
}
